package tests;

import java.util.TreeSet;

import tester.Example;
import tester.ExampleWrapper;
import tester.Main;
import tester.TestMethod;
import tester.Tester;

@Example
public class CommandLineTests {

	@TestMethod
	public void testCommandProcessor(Tester t){
		String myArgs[] = {"-p", "pack1", "-n", "goodclass", "-n", "betterclass"};
		String myArgs2[] = {"-n", "okayclass", "-n", "goodclass", "-n", "betterclass"};
		String badArgs[] = {"Badcode"};
		String badArgs2[] = {""};
		String badArgs3[] = {"-p", "packagename", "kablooie"};
		String badArgs4[] = {"p", "packagename", "kablooie"};
		
		IllegalArgumentException exception = new IllegalArgumentException("Improper format of command line arguments.");

		TreeSet<ExampleWrapper> goodRes = new TreeSet<ExampleWrapper>();
		goodRes.add(new ExampleWrapper("pack1", "goodclass"));
		goodRes.add(new ExampleWrapper("", "betterclass"));
		
		TreeSet<ExampleWrapper> goodRes2 = new TreeSet<ExampleWrapper>();
		goodRes2.add(new ExampleWrapper("", "okayclass"));
		goodRes2.add(new ExampleWrapper("", "goodclass"));
		goodRes2.add(new ExampleWrapper("", "betterclass"));

		t.checkExpect(Main.processCommandLineArgs(myArgs), goodRes);
		t.checkExpect(Main.processCommandLineArgs(myArgs2), goodRes2);
		
		try{
			t.checkExpect(Main.processCommandLineArgs(badArgs), exception);
			t.fail();
		} catch(IllegalArgumentException e){
			t.checkExpect(e, exception);
		}
		
		try{
			t.checkExpect(Main.processCommandLineArgs(badArgs2), exception);
			t.fail();
		} catch(IllegalArgumentException e){
			t.checkExpect(e, exception);
		}
		
		try{
			t.checkExpect(Main.processCommandLineArgs(badArgs3), exception);
			t.fail();
		} catch(IllegalArgumentException e){
			t.checkExpect(e, exception);
		}
		
		try{
			t.checkExpect(Main.processCommandLineArgs(badArgs4), exception);
			t.fail();
		} catch(IllegalArgumentException e){
			t.checkExpect(e, exception);
		}
	}
	
	@TestMethod
	public void testExamplePaths(Tester t){
		String myArgs[] = {"-p", "pack1", "-n", "goodclass", "-n", "betterclass"};
		String myArgs2[] = {"-n", "okayclass", "-n", "goodclass", "-n", "betterclass"};
		String myArgs3[] = {"-p", "extrapack", "-n", "okayclass", "-n", "goodclass", "-p", "pack2", "-n", "betterclass"};

		TreeSet<ExampleWrapper> ts1 = Main.processCommandLineArgs(myArgs);
		TreeSet<ExampleWrapper> ts2 = Main.processCommandLineArgs(myArgs2);
		TreeSet<ExampleWrapper> ts3 = Main.processCommandLineArgs(myArgs3);

		String[] ts1strings = {"betterclass", "pack1.goodclass"};
		String[] ts2strings = {"betterclass", "goodclass", "okayclass"};
		String[] ts3strings = {"goodclass", "extrapack.okayclass", "pack2.betterclass"};

		t.checkExpect(Main.examplePaths(ts1), ts1strings);
		t.checkExpect(Main.examplePaths(ts2), ts2strings);
		t.checkExpect(Main.examplePaths(ts3), ts3strings);
	}
}